﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace PriceCuttingWar
{
	public partial class HighestScore : UserControl
	{
        int _score1
        {
            set
            {
                Score1.Text = value.ToString();
            }
        }
        int _score2
        {
            set
            {
                Score2.Text = value.ToString();
            }
        }
        int _score3
        {
            set
            {
                Score3.Text = value.ToString();
            }
        }
		public HighestScore()
		{
			InitializeComponent();
            GSystem.HighestScore = this;
            Btn_Back.Click += new RoutedEventHandler(Btn_Back_Click);
            ANI_Start.Completed += (s, e) =>
                {
                    this.Visibility = System.Windows.Visibility.Collapsed;
                    //var t = new Microsoft.Phone.Tasks.MarketplaceDetailTask();
                    //t.Show();
                };
		}
        void Btn_Back_Click(object sender, RoutedEventArgs e)
        {
            Hide();
        }
        public void Show()
        {
            this.Visibility = System.Windows.Visibility.Visible;
            ANI_Show.Begin();
            IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;
            if (storage.Contains(EmGameMode.Money.ToString()))
                _score1 = (int)storage[EmGameMode.Money.ToString()];
            else
                _score1 = 0;
            if (storage.Contains(EmGameMode.Cutting.ToString()))
                _score2 = (int)storage[EmGameMode.Cutting.ToString()];
            else
                _score2 = 0;
            if (storage.Contains(EmGameMode.And.ToString()))
                _score3 = (int)storage[EmGameMode.And.ToString()];
            else
                _score3 = 0;
            
        }
        public void Hide()
        {
            ANI_Start.Begin();
            //this.Visibility = System.Windows.Visibility.Collapsed;
        }
        public int GetHighestScore(EmGameMode mode)
        {
            int s = 0;
            IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;
            if (storage.Contains(mode.ToString()))
                s = (int)storage[mode.ToString()];
            return s;
        }
        public void SaveHighestScore(EmGameMode mode, int score)
        {
            IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;
            if (storage.Contains(mode.ToString()))
                storage[mode.ToString()] = score;
            else
                storage.Add(mode.ToString(), score);
            storage.Save();
        }
	}
}